package StructuralMode.proxy.proxyCGLIB.railwayStation;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class RailwayStationProxy implements MethodInterceptor {

    private RailwayStationReal railwayStationReal = new RailwayStationReal();

    public RailwayStationReal createProxy(){
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(RailwayStationReal.class);
        enhancer.setCallback(this);

        RailwayStationReal railwayStationReal = (RailwayStationReal) enhancer.create();
        return railwayStationReal;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
         System.out.println("买票钱的操作");
         return method.invoke(railwayStationReal,objects);
    }
}
